/* Main window */

#include <QtGui>
#include "URLDialog.h"
#include "SpideyWindow.h"
#include "Nodes.h"

#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QPainter>
#include <QObject>



SpideyWindow::SpideyWindow(/*QWidget *parent*/)      // default: *parent = 0
{
    scene = new QGraphicsScene(this);
    scene -> setSceneRect(-300, -300, 600, 600);
    scene -> setItemIndexMethod(QGraphicsScene::NoIndex);

	node *node1 = new node(10, 200, 200, this);
node1->moveBy(-100,-100);

/*
    // I use this test a lot when messing with the node's scene stuff to ensure
    // that parent is what it should be. - DVirus
    if(node1->scene() == 0) {
        QMessageBox::information(this, "scene", "scene = 0");
    }
    else {
        QMessageBox::information(this, "scene", "scene = something");
    }
*/

    QGraphicsView *view = new QGraphicsView(scene);
    view -> setRenderHint(QPainter::Antialiasing);
    view -> setCacheMode(QGraphicsView::CacheBackground);
    view -> setDragMode(QGraphicsView::ScrollHandDrag);

    setCentralWidget(view);
    setWindowTitle(tr("Spideypedia"));
    resize(WINDOWXRES, WINDOWYRES);
    createActions();
    createMenus();
}

void SpideyWindow::addNode(node *addMe)
{
    scene->addItem(addMe);
}

void SpideyWindow::runUrlDialog()
{
    urlDialog dialog(this);
    dialog.exec();
}

void SpideyWindow::about()
{
    QMessageBox::about(this, tr("About Spideypedia"),
                tr("<b>Spideypedia</b>"
                   "<br>An opensource tool for "
                   "the visualization of Wikipedia. <br>"
                   "http://code.google.com/p/spideypedia/ <br>"
                   "<br> fonz2591@gmail.com <br>"
                   "DVirus101@gmail.com"));
    QMessageBox::information(this, tr("scene"),
                            tr("%1 items in scene").arg(scene->items().size()));
}

void SpideyWindow::createActions()
{
    exitAct = new QAction(tr("E&xit"), this);
    exitAct -> setShortcut(tr("Ctrl+Q"));
    exitAct -> setStatusTip(tr("Exit the application"));
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

    urlDialogAct = new QAction(tr("&Edit Url(s)"), this);
    urlDialogAct -> setShortcut(tr("Ctrl+O"));
    urlDialogAct -> setStatusTip(tr("Select the starting Url's for spideypedia"));
    connect(urlDialogAct, SIGNAL(triggered()), this, SLOT(runUrlDialog()));

    aboutAct = new QAction(tr("&About"), this);
    aboutAct -> setStatusTip(tr("Show the application's About box"));
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

}

void SpideyWindow::createMenus()
{
	fileMenu = menuBar() -> addMenu(tr("&File"));
	fileMenu -> addAction(exitAct);

	editMenu = menuBar() -> addMenu(tr("&Edit"));
	editMenu -> addAction(urlDialogAct);

	helpMenu = menuBar() -> addMenu(tr("&Help"));
	helpMenu -> addAction(aboutAct);
}


